import os
import tensorflow as tf

# First step: download the data set
BASE_DIR = "D:/tmp/model-training/"
IMAGE_DATA_DIR = BASE_DIR + "image"
OUTPUT_DIR = BASE_DIR + "output"
file_names = []


def get_images():
    for path, subdirs, files in os.walk(IMAGE_DATA_DIR):
        for file_name in files:
            file_names.append(file_name)


def _int64_feature(value):
    return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))


def _bytes_feature(value):
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))


def load_images():
    file_queue = tf.train.string_input_producer(file_names)
    reader = tf.WholeFileReader()
    file_name, content = reader.read(file_queue)
    image = tf.image.decode_jpeg(content, channels=3)
    image = tf.cast(image, tf.float32)
    resized_image = tf.image.resize_images(image, [200, 200])

    image_batch = tf.train.batch([resized_image], batch_size=10)


def transform_to_tfrecord():
    if not os.path.exists(OUTPUT_DIR) or os.path.isfile(OUTPUT_DIR):
        os.makedirs(OUTPUT_DIR)


get_images()
load_images()

with tf.Session() as sess:
    init_ops = tf.initialize_all_variables()
    sess.run(init_ops)
